import React from 'react';
import { Form, Input, Button, message } from 'antd';
import { request } from 'umi';



const Add = () => {
  const container = { padding: "20px", height: "100%" };
  const css2 = { background: "white", padding: "20px" }

  
  const onFinish = (values) => {
    let params = new URLSearchParams()
    params.append("index", values.index)
    params.append("name", values.name)
    console.log(values);
    request("http://www.young1024.com:1717/v1/table/add", {
      data: params,
      method: 'POST',
      headers: {
        token: JSON.parse(localStorage.getItem("token"))
      },
    }).then(
      (res) => {
        console.log(res);
        if (res.status === "success") {
          message.info('添加成功');
        }
      },
      (err) => { console.log(err); }
    )
  };

  const onFinishFailed = (errorInfo) => {
    console.log('Failed:', errorInfo);
  };

  return (
    <div style={container}>
      <div style={css2}>
        <h2 style={{ padding: "20px 0 0 20px" }}>新增台桌</h2>
        <Form
          name="basic"
          labelCol={{
            span: 4,
          }}
          wrapperCol={{
            span: 4,
          }}
          initialValues={{
            remember: true,
          }}
          onFinish={onFinish}
          onFinishFailed={onFinishFailed}
          autoComplete="off"
        >
          <Form.Item
            label="序号"
            name="index"
            rules={[
              {
                required: true,
                message: '请输入序号!',
              },
            ]}
          >
            <Input />
          </Form.Item>

          <Form.Item
            label="名称"
            name="name"
            rules={[
              {
                required: true,
                message: '请输入名称!',
              },
            ]}
          >
            <Input />
          </Form.Item>

          <Form.Item
            wrapperCol={{
              offset: 4,
              span: 4,
            }}
          >
            <Button type="primary" htmlType="submit">
              添加
            </Button>
          </Form.Item>

        </Form>
      </div>
    </div>
  );
}

export default Add;
